package com.dianning.service.imp;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

import org.apache.commons.logging.*;

import com.dianning.bean.AdSpace;
import com.dianning.bean.Credit;
import com.dianning.bean.Visitor;
import com.dianning.dao.AdAdsDAO;
import com.dianning.dao.AdSpaceDAO;
import com.dianning.dao.CreditDAO;
import com.dianning.dao.VisitorDAO;
import com.dianning.exception.DianningException;
import com.dianning.service.AdService;
import com.dianning.service.CreditService;
import com.dianning.service.VisitorService;

public class CreditServiceImp implements CreditService {

	private static final Log logger = LogFactory.getLog(CreditServiceImp.class);
	
	private CreditDAO creditDAO;

	public CreditDAO getCreditDAO() {
		return creditDAO;
	}

	public void setCreditDAO(CreditDAO creditDAO) {
		this.creditDAO = creditDAO;
	}


	/**
	 * 创建奖励记录
	 * @param credit
	 * 			Credit对象
	 * @return Credit
	 * 			Credit对象
	 */
	public Credit createCredit(Credit credit){
		if(credit.getId() == 0){
			return this.getCreditDAO().saveCredit(credit);
		}else{
			return this.getCreditDAO().updateCredit(credit);
		}
	}

	/**
	 * 根据code获取过期一天Credit对象
	 * @param code
	 * @return Credit
	 */
	public Credit findCreditByUidCodeTime(long uid,String code){
		return this.getCreditDAO().findCreditByUidCodeTime(uid, code);
	}
	
	/**
	 * 根据code获取过期一天Credit对象
	 * @param code
	 * @return Credit
	 */
	public Credit findCreditByUidCodeDate(long uid,String code){
		return this.getCreditDAO().findCreditByUidCodeDate(uid, code);
	}
	/**
	 * 根据code获取Credit对象
	 * @param code
	 * @return Credit
	 */
	public Credit findCreditByUidCode(long uid,String code){
		return this.getCreditDAO().findCreditByUidCode(uid, code);
	}
}
